﻿using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.LogEntries;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem
{
	// Token: 0x0200004E RID: 78
	public class CampaignInformationManager
	{
		// Token: 0x0600079F RID: 1951 RVA: 0x00022AD4 File Offset: 0x00020CD4
		private void MapNoticeRemoved(InformationData obj)
		{
			int num = -1;
			for (int i = 0; i < this._mapNotices.Count; i++)
			{
				if (obj == this._mapNotices[i])
				{
					num = i;
				}
			}
			if (num >= 0)
			{
				this._mapNotices.RemoveAt(num);
			}
		}

		// Token: 0x060007A0 RID: 1952 RVA: 0x00022B1A File Offset: 0x00020D1A
		public CampaignInformationManager()
		{
			this._mapNotices = new List<InformationData>();
		}

		// Token: 0x060007A1 RID: 1953 RVA: 0x00022B30 File Offset: 0x00020D30
		internal void NewLogEntryAdded(LogEntry log)
		{
			IChatNotification chatNotification;
			if (this._isSessionLaunched && (chatNotification = (log as IChatNotification)) != null && chatNotification.IsVisibleNotification)
			{
				InformationManager.DisplayMessage(new InformationMessage
				{
					Information = chatNotification.GetNotificationText().ToString(),
					Color = Color.FromUint(Campaign.Current.Models.DiplomacyModel.GetNotificationColor(chatNotification.NotificationType))
				});
			}
		}

		// Token: 0x060007A2 RID: 1954 RVA: 0x00022B97 File Offset: 0x00020D97
		private void AddInformationData(InformationData informationData)
		{
			List<InformationData> mapNotices = this._mapNotices;
			if (mapNotices != null)
			{
				mapNotices.Add(informationData);
			}
			MBInformationManager.AddNotice(informationData);
		}

		// Token: 0x060007A3 RID: 1955 RVA: 0x00022BB1 File Offset: 0x00020DB1
		internal void RegisterEvents()
		{
			this._isSessionLaunched = true;
			MBInformationManager.OnRemoveMapNotice += this.MapNoticeRemoved;
		}

		// Token: 0x060007A4 RID: 1956 RVA: 0x00022BCB File Offset: 0x00020DCB
		internal void DeRegisterEvents()
		{
			this._isSessionLaunched = false;
			MBInformationManager.OnRemoveMapNotice -= this.MapNoticeRemoved;
		}

		// Token: 0x060007A5 RID: 1957 RVA: 0x00022BE8 File Offset: 0x00020DE8
		public void OnGameLoaded()
		{
			this._mapNotices.RemoveAll((InformationData t) => t == null || !t.IsValid());
			foreach (InformationData data in this._mapNotices)
			{
				MBInformationManager.AddNotice(data);
			}
		}

		// Token: 0x060007A6 RID: 1958 RVA: 0x00022C64 File Offset: 0x00020E64
		public void NewMapNoticeAdded(InformationData informationData)
		{
			this.AddInformationData(informationData);
		}

		// Token: 0x060007A7 RID: 1959 RVA: 0x00022C70 File Offset: 0x00020E70
		public bool InformationDataExists<T>(Func<T, bool> predicate) where T : InformationData
		{
			using (List<InformationData>.Enumerator enumerator = this._mapNotices.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					T arg;
					if ((arg = (enumerator.Current as T)) != null && (predicate == null || predicate(arg)))
					{
						return true;
					}
				}
			}
			return false;
		}

		// Token: 0x060007A8 RID: 1960 RVA: 0x00022CE4 File Offset: 0x00020EE4
		internal static void AutoGeneratedStaticCollectObjectsCampaignInformationManager(object o, List<object> collectedObjects)
		{
			((CampaignInformationManager)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x060007A9 RID: 1961 RVA: 0x00022CF2 File Offset: 0x00020EF2
		protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			collectedObjects.Add(this._mapNotices);
		}

		// Token: 0x060007AA RID: 1962 RVA: 0x00022D00 File Offset: 0x00020F00
		internal static object AutoGeneratedGetMemberValue_mapNotices(object o)
		{
			return ((CampaignInformationManager)o)._mapNotices;
		}

		// Token: 0x0400028E RID: 654
		[SaveableField(10)]
		private List<InformationData> _mapNotices;

		// Token: 0x0400028F RID: 655
		[CachedData]
		private bool _isSessionLaunched;

		// Token: 0x02000496 RID: 1174
		public enum NoticeType
		{
			// Token: 0x040013DE RID: 5086
			None,
			// Token: 0x040013DF RID: 5087
			WarAnnouncement,
			// Token: 0x040013E0 RID: 5088
			PeaceAnnouncement,
			// Token: 0x040013E1 RID: 5089
			ChangeSettlementOwner,
			// Token: 0x040013E2 RID: 5090
			FortificationIsCaptured,
			// Token: 0x040013E3 RID: 5091
			HeroChangedFaction,
			// Token: 0x040013E4 RID: 5092
			BarterAnnouncement
		}
	}
}
